home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / misc / 39 / do_wear2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-07-17  |  5.8 KB  |  248 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* do_wear.c - version 1.0.3 */
  3.  
  4. #include <stdio.h>
  5. #include "hack.h"
  6. extern char *nomovemsg;
  7. extern char quitchars[];
  8. extern char *Doname2();
  9.  
  10.  
  11. doweararm() {
  12.     register struct obj *otmp;
  13.     register int delay;
  14.     register int err = 0;
  15.     long mask = 0;
  16.  
  17.     otmp = getobj("[", "wear");
  18.     if(!otmp) return(0);
  19.     if(otmp->owornmask & W_ARMOR) {
  20.         pline("You are already wearing that!");
  21.         return(0);
  22.     }
  23.     if(otmp->otyp == HELMET){
  24.         if(uarmh) {
  25.             pline("You are already wearing a helmet.");
  26.             err++;
  27.         } else
  28.             mask = W_ARMH;
  29.     } else if(otmp->otyp == SHIELD){
  30.         if(uarms) pline("You are already wearing a shield."), err++;
  31.         if(uwep && uwep->otyp == TWO_HANDED_SWORD)
  32.     pline("You cannot wear a shield and wield a two-handed sword."), err++;
  33.         if(!err) mask = W_ARMS;
  34.     } else if(otmp->otyp == PAIR_OF_GLOVES) {
  35.         if(uarmg) {
  36.             pline("You are already wearing gloves.");
  37.             err++;
  38.         } else
  39.         if(uwep && uwep->cursed) {
  40.             pline("You cannot wear gloves over your weapon.");
  41.             err++;
  42.         } else
  43.             mask = W_ARMG;
  44.     } else {
  45.         if(uarm) {
  46.             if(otmp->otyp != ELVEN_CLOAK || uarm2) {
  47.                 pline("You are already wearing some armor.");
  48.                 err++;
  49.             }
  50.         }
  51.         if(!err) mask = W_ARM;
  52.     }
  53.     if(otmp == uwep && uwep->cursed) {
  54.         if(!err++)
  55.             pline("%s is welded to your hand.", Doname2(uwep));
  56.     }
  57.     if(err) return(0);
  58.     setworn(otmp, mask);
  59.     if(otmp == uwep)
  60.         setuwep((struct obj *) 0);
  61.     delay = -objects[otmp->otyp].oc_delay;
  62.     if(delay){
  63.         nomul(delay);
  64.         nomovemsg = "You finished your dressing manoeuvre.";
  65.     }
  66.     otmp->known = 1;
  67.     return(1);
  68. }
  69.  
  70. dowearring() {
  71.     register struct obj *otmp;
  72.     long mask = 0;
  73.     long oldprop;
  74.  
  75.     if(uleft && uright){
  76.         pline("There are no more ring-fingers to fill.");
  77.         return(0);
  78.     }
  79.     otmp = getobj("=", "wear");
  80.     if(!otmp) return(0);
  81.     if(otmp->owornmask & W_RING) {
  82.         pline("You are already wearing that!");
  83.         return(0);
  84.     }
  85.     if(otmp == uleft || otmp == uright) {
  86.         pline("You are already wearing that.");
  87.         return(0);
  88.     }
  89.     if(otmp == uwep && uwep->cursed) {
  90.         pline("%s is welded to your hand.", Doname2(uwep));
  91.         return(0);
  92.     }
  93.     if(uleft) mask = RIGHT_RING;
  94.     else if(uright) mask = LEFT_RING;
  95.     else do {
  96.         char answer;
  97.  
  98.          pline("What ring-finger, Right or Left? ");
  99.         if(index(quitchars, (answer = readchar())))
  100.             return(0);
  101.         switch(answer){
  102.         case 'l':
  103.         case 'L':
  104.             mask = LEFT_RING;
  105.             break;
  106.         case 'r':
  107.         case 'R':
  108.             mask = RIGHT_RING;
  109.             break;
  110.         }
  111.     } while(!mask);
  112.     setworn(otmp, mask);
  113.     if(otmp == uwep)
  114.         setuwep((struct obj *) 0);
  115.     oldprop = u.uprops[PROP(otmp->otyp)].p_flgs;
  116.     u.uprops[PROP(otmp->otyp)].p_flgs |= mask;
  117.     switch(otmp->otyp){
  118.     case RIN_LEVITATION:
  119.         if(!oldprop) float_up();
  120.         break;
  121.     case RIN_PROTECTION_FROM_SHAPE_CHANGERS:
  122.         rescham();
  123.         break;
  124.     case RIN_GAIN_STRENGTH:
  125.         u.ustr += otmp->spe;
  126.         u.ustrmax += otmp->spe;
  127.         if(u.ustr > 118) u.ustr = 118;
  128.         if(u.ustrmax > 118) u.ustrmax = 118;
  129.         flags.botl = 1;
  130.         break;
  131.     case RIN_INCREASE_DAMAGE:
  132.         u.udaminc += otmp->spe;
  133.         break;
  134.     }
  135.     prinv(otmp);
  136.     return(1);
  137. }
  138.  
  139. ringoff(obj)
  140. register struct obj *obj;
  141. {
  142. register long mask;
  143.     mask = obj->owornmask & W_RING;
  144.     setworn((struct obj *) 0, obj->owornmask);
  145.     if(!(u.uprops[PROP(obj->otyp)].p_flgs & mask))
  146.         impossible("Strange... I didnt know you had that ring.");
  147.     u.uprops[PROP(obj->otyp)].p_flgs &= ~mask;
  148.     switch(obj->otyp) {
  149.     case RIN_FIRE_RESISTANCE:
  150.         /* Bad luck if the player is in hell... --jgm */
  151.         if (!Fire_resistance && dlevel >= 30) {
  152.             pline("The flames of Hell burn you to a crisp.");
  153.             killer = "stupidity in hell";
  154.             done("burned");
  155.         }
  156.         break;
  157.     case RIN_LEVITATION:
  158.         if(!Levitation) {    /* no longer floating */
  159.             float_down();
  160.         }
  161.         break;
  162.     case RIN_GAIN_STRENGTH:
  163.         u.ustr -= obj->spe;
  164.         u.ustrmax -= obj->spe;
  165.         if(u.ustr > 118) u.ustr = 118;
  166.         if(u.ustrmax > 118) u.ustrmax = 118;
  167.         flags.botl = 1;
  168.         break;
  169.     case RIN_INCREASE_DAMAGE:
  170.         u.udaminc -= obj->spe;
  171.         break;
  172. #ifdef DGK
  173.     case RIN_PROTECTION_FROM_SHAPE_CHANGERS:
  174.         /* If you're no longer protected, let the chameleons
  175.          * change shape again -dgk
  176.          */
  177.         restartcham();
  178.         break;
  179. #endif DGK
  180.     }
  181. }
  182.  
  183. find_ac(){
  184. register int uac = 10;
  185.     if(uarm) uac -= ARM_BONUS(uarm);
  186.     if(uarm2) uac -= ARM_BONUS(uarm2);
  187.     if(uarmh) uac -= ARM_BONUS(uarmh);
  188.     if(uarms) uac -= ARM_BONUS(uarms);
  189.     if(uarmg) uac -= ARM_BONUS(uarmg);
  190.     if(uleft && uleft->otyp == RIN_PROTECTION) uac -= uleft->spe;
  191.     if(uright && uright->otyp == RIN_PROTECTION) uac -= uright->spe;
  192.     if(uac != u.uac){
  193.         u.uac = uac;
  194.         flags.botl = 1;
  195.     }
  196. }
  197.  
  198. glibr(){
  199. register struct obj *otmp;
  200. int xfl = 0;
  201.     if(!uarmg) if(uleft || uright) {
  202.         /* Note: at present also cursed rings fall off */
  203.         pline("Your %s off your fingers.",
  204.             (uleft && uright) ? "rings slip" : "ring slips");
  205.         xfl++;
  206.         if((otmp = uleft) != Null(obj)){
  207.             ringoff(uleft);
  208.             dropx(otmp);
  209.         }
  210.         if((otmp = uright) != Null(obj)){
  211.             ringoff(uright);
  212.             dropx(otmp);
  213.         }
  214.     }
  215.     if((otmp = uwep) != Null(obj)){
  216.         /* Note: at present also cursed weapons fall */
  217.         setuwep((struct obj *) 0);
  218.         dropx(otmp);
  219.         pline("Your weapon %sslips from your hands.",
  220.             xfl ? "also " : "");
  221.     }
  222. }
  223.  
  224. struct obj *
  225. some_armor(){
  226. register struct obj *otmph = uarm;
  227.     if(uarmh && (!otmph || !rn2(4))) otmph = uarmh;
  228.     if(uarmg && (!otmph || !rn2(4))) otmph = uarmg;
  229.     if(uarms && (!otmph || !rn2(4))) otmph = uarms;
  230.     return(otmph);
  231. }
  232.  
  233. corrode_armor(){
  234. register struct obj *otmph = some_armor();
  235.     if(otmph){
  236.         if(otmph->rustfree ||
  237.            otmph->otyp == ELVEN_CLOAK ||
  238.            otmph->otyp == LEATHER_ARMOR ||
  239.            otmph->otyp == STUDDED_LEATHER_ARMOR) {
  240.             pline("Your %s not affected!",
  241.                 aobjnam(otmph, "are"));
  242.             return;
  243.         }
  244.         pline("Your %s!", aobjnam(otmph, "corrode"));
  245.         otmph->spe--;
  246.     }
  247. }
  248.